<?php


namespace App\Models;


class ChatRoomUser extends BaseModel
{
    protected $table = 'chat_room_user';

    protected $fillable = [
        "user_id",
        "room_id",
        "name_note",
        "read_message_id",
    ];

    public function user()
    {
        return $this->hasOne('App\Models\User', 'id', 'user_id');
    }

    public static function saveReadMessageID($user_id, $room_id, $read_message_id)
    {
        $chatRoomUser = ChatRoomUser::where('user_id', $user_id)->where('room_id', $room_id)->first();
        $chatRoomUser->read_message_id = $read_message_id;
        $chatRoomUser->save();
    }
}
